import { s_getcommontableinfo, s_getPurchaseInfo, status2text } from "@/services/basis";
import { ProCard, ProColumns, ProTable } from "@ant-design/pro-components";
import { Button, Space, Tag ,Image} from "antd";
import { useState } from "react";

const App:React.FC=()=>{
    const [total,setTotal]=useState(0);
    interface DataType{
//         x_id,org_id,vouch_code,vendor_id,vouch_status,operate_time,
// material_id,userdefine_name,quantity,deliverdate,
// code,name,invstd,invstd2,munit_name,
// org_name,vendor_name,operater_name,
// quantity_deliver,quantity_reback,quantity_stockin,progress_stockin

taskcard_sno?:string,quantity?:number,quantity_done?:number,code?:string,name?:string,quantity_undone?:number,
invstd?:string,munit_name?:string,taskcard_name?:string,vendor?:string,do_progress?:number,pic?:string,
    };

    const columns:ProColumns<DataType>[]=[
        {dataIndex:'pic',title:'图片' ,editable:false,search:false,width:80,
          //     render:(text)=>{
          //         var pic=text=="-"||text==undefined?"":"/basis_api/file/get?filename="+text;
          //         return <Image src={pic}  
          //                style={{width:50,height:50}} alt='无' />
          //    },
          //  },
          render:(text,record,index,k)=>{
                         var pic="/basis_api/file/get2?filename="+record.code;
                         return   <Image src={pic}  style={{width:50,height:50}} alt='无' />
       }},
       {dataIndex:'vendor',title:'外发商',width:100},
       {dataIndex:'taskcard_sno',title:'工序卡号',width:100},

        {dataIndex:'code',title:'SKU编码',width:160,},
        {dataIndex:'name',title:'商品名称',width:'20%'},
        {dataIndex:'invstd',title:'包装规格',search:false,width:'20%'},
        // {dataIndex:'userdefine_name',title:'自定义项'},
        {dataIndex:'munit_name',title:'计量单位',search:false,width:80},
        {dataIndex:'quantity',title:'总数量',search:false,width:80},
        {dataIndex:'quantity_done',title:'完成数量',search:false,width:80},
        {dataIndex:'quantity_undone',title:'未完数量',search:false,width:80},
        {dataIndex:'do_progress',title:'完成比例',
          valueType:'progress',width:'25%',search:false,
          // render:(text,record)=>Math.floor((record.quantity_done?record.quantity_done:0)/(record.quantity?record.quantity:1)*100)
        },
        
    ];

    
    //==============================================================================================================
    return <>
      <ProCard title='外发进度跟踪' style={{height:'85vh',overflow:'auto'}}
        //  extra={<Space>
        //     <Button>查看采购齐套</Button>
        //     <Button>查看入库明细</Button>
             
        //  </Space>}
      >
          <ProTable<DataType>
             columns={columns}
            //  dataSource={tdata}
             search={{span:4}}
            //  rowSelection={{
            //     type:'checkbox'
            //  }}
             rowKey='id'
             options={false}
            //  request={async ()=>{
            //     // x_id,cate_id,id,source,fdata
            //     const x=await s_getcommontableinfo({x_id:1,cate_id:[],id:0,source:'v_purchase_order_progress',fdata:null});
            //     return {
            //         data:x.data[0],
            //         success:true,
            //     }
            //  }}
              // v_sale_order_main
             request={async (param)=>{
                  const x=await s_getPurchaseInfo({source:'v_taskcard_reporting',x_id:1,
                                               fdata:{id:0,param}});
                  setTotal(x.data[0][0].count);
                  return{
                         data:x.data[1],
                         success:true,
                         }
                 }}
          scroll={{y:'65vh'}}
                    pagination={{
                    showQuickJumper:true,
                    showSizeChanger:true,
                    defaultPageSize:10,
                    defaultCurrent:1,
                    total,
                  }}
          /> 
      </ProCard> 
    </>;
}

export default App;